/*
 * Jp_Messages.java
 *
 * Created on 30 avril 2008, 15:18
 */

package gui;

import java.util.GregorianCalendar;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author  olivierm
 */
public class Jp_Messages extends javax.swing.JPanel {
    
    DefaultListModel _modele = new DefaultListModel();
    
    
    public void nouveauMessage(String message){
        GregorianCalendar d = new GregorianCalendar();
        this._modele.addElement(d.getTime().toString() + ": " + message);
    }
    
    /** Creates new form Jp_Messages */
    public Jp_Messages() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTitledPanel1 = new org.jdesktop.swingx.JXTitledPanel();
        jToolBar1 = new javax.swing.JToolBar();
        jbtn_Effacer = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXList1 = new org.jdesktop.swingx.JXList();
        jPanel1 = new javax.swing.JPanel();
        jbtn_Annuler = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jXTitledPanel1.getContentContainer().setLayout(new java.awt.BorderLayout());

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        jbtn_Effacer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cancel.png"))); // NOI18N
        jbtn_Effacer.setText("Effacer");
        jbtn_Effacer.setFocusable(false);
        jbtn_Effacer.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jbtn_Effacer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbtn_Effacer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_EffacerActionPerformed(evt);
            }
        });
        jToolBar1.add(jbtn_Effacer);
        jToolBar1.add(jSeparator1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/database_refresh.png"))); // NOI18N
        jButton1.setText("Rafraichir");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jXTitledPanel1.getContentContainer().add(jToolBar1, java.awt.BorderLayout.NORTH);

        jXList1.setModel(_modele);
        jScrollPane1.setViewportView(jXList1);

        jXTitledPanel1.getContentContainer().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jbtn_Annuler.setText("Annuler");
        jbtn_Annuler.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtn_AnnulerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(371, Short.MAX_VALUE)
                .addComponent(jbtn_Annuler)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtn_Annuler)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jXTitledPanel1.getContentContainer().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        add(jXTitledPanel1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtn_AnnulerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_AnnulerActionPerformed

    this.setVisible(false);
        
}//GEN-LAST:event_jbtn_AnnulerActionPerformed

    private void jbtn_EffacerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_EffacerActionPerformed

        if (JOptionPane.showConfirmDialog(null, "Etes vous sure de vouloir supprimer les messages?","Question",JOptionPane.YES_NO_OPTION ) == 0)
            this._modele.removeAllElements();
        
    }//GEN-LAST:event_jbtn_EffacerActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.swingx.JXList jXList1;
    private org.jdesktop.swingx.JXTitledPanel jXTitledPanel1;
    private javax.swing.JButton jbtn_Annuler;
    private javax.swing.JButton jbtn_Effacer;
    // End of variables declaration//GEN-END:variables
    
}
